package com.example.hello.service.impl;

import com.example.hello.mapper.InteractionMapper;
import com.example.hello.service.RatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RatingServiceImpl implements RatingService {

    @Autowired
    private InteractionMapper interactionMapper;

    @Override
    public Double getRating(Integer userId, Integer bookId) {
        Double rating = interactionMapper.getRatingByUserAndBook(userId, bookId);
        if (rating == null) {
            // 没查到则返回 0
            rating = 0.0;
        }
        return rating;
    }
}